package com.yc.pay.controller;

import com.yc.pay.api.req.NetBankPayReq;
import com.yc.pay.api.resp.NetBankPayData;
import com.yc.pay.api.resp.RespVo;
import com.yc.pay.service.InetBankPayService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 网银支付接口
 */
@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private InetBankPayService netBankPayService;

    private static final Logger logger = LoggerFactory.getLogger(PayController.class);

    /**
     * 网银支付(需要跳转页面)统一接口
     * @param netBankPayReq
     * @return
     */
    @RequestMapping("/netBankPay")
    public RespVo<NetBankPayData> netBankPay(@RequestBody NetBankPayReq netBankPayReq){
        logger.info("##########接受到业务系统的支付请求，请求的参数：{}##########",netBankPayReq);

        // 空判断
        if (StringUtils.isEmpty(netBankPayReq.getAmount())){
            return RespVo.returnFailRespVo("金额为空");
        }

        //业务逻辑处理
        RespVo<NetBankPayData> respVo = netBankPayService.netBankPay(netBankPayReq);
        logger.info("##########处理完成支付请求，返回参数：{}##########",respVo);
        return respVo;
    }



}
